package com.android.questions.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.android.base.util.ActivityClickUtil;
import com.android.base.util.DisplayUtil;
import com.android.questions.R;
import com.android.questions.databinding.DialogHpTipBinding;

public class DialogHpTip extends Dialog implements View.OnClickListener {

    private DialogHpTipBinding binding;
    private final Activity activity;

    public DialogHpTip(Activity a) {
        super(a, R.style.dialog_loading);
        this.activity = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogHpTipBinding.inflate(activity.getLayoutInflater());
        setContentView(binding.getRoot());

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = DisplayUtil.getScreenWidth(activity);
        lp.height = DisplayUtil.getScreenHeight(activity);
        getWindow().setAttributes(lp);

        getWindow().setWindowAnimations(R.style.dialog_answer_correct);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
        initView();
        initLister();
    }

    private void initView() {
        ActivityClickUtil.getInstance().clear();
    }

    private void initLister() {
        binding.ivClose.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (ActivityClickUtil.getInstance().isFastClick()) {
            //防止用户快速点击
            return;
        }
        dismiss();
    }
}
